package com.example.rootwar.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@RequestMapping(value = "test")
@RestController
public class TestComtroller {

    static Logger logger= LogManager.getLogger("Console");

    @RequestMapping(value = "getName",method = {RequestMethod.POST,RequestMethod.GET})
    public String getName(){
        return "1234";
    }

    @RequestMapping(value = "two",method = {RequestMethod.POST,RequestMethod.GET})
    public Map two(){

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();

        logger.info("come:{}","123");

        String name="${java:os}";
        logger.info("come1:{}!",name);




        objectObjectHashMap.put("code123",200);
        objectObjectHashMap.put("msg","操作成功！！！");
        objectObjectHashMap.put("uuid23", UUID.randomUUID().toString());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        objectObjectHashMap.put("data1", simpleDateFormat.format(new Date()));
        return objectObjectHashMap;
    }


    public static void main(String[] args) {
        System.out.println(buddyStrings("aa", "aa"));
    }

    public static boolean buddyStrings(String s, String goal) {

        char[] chars = s.toCharArray();
        char[] chars1 = goal.toCharArray();
        if (chars.length!=goal.length()||s.length()==1){
            return false;
        }
        int count=0;

        HashMap<Character, Integer> objectObjectHashMap = new HashMap<>();

        //2个不同 互换相同
        int a1=0,a2=0,a3=0,a4 = 0;
        for (int i = 0; i < chars.length; i++) {
            char aChar = chars[i];
            char aChar1 = chars1[i];

            objectObjectHashMap.put(aChar,objectObjectHashMap.getOrDefault(aChar,0)+1);
            if (aChar!=aChar1){
                count++;
                if (count==1){
                    a1=aChar;
                    a2=aChar1;
                }
                if (count==2){
                    a3=aChar;
                    a4=aChar1;
                }
            }

            if (count>2){
                return false;
            }
        }

        if (count==2){
            if (a1==a4 && a2==a3){
                return true;
            }
        }
        if (count==0){
            Set<Map.Entry<Character, Integer>> entries = objectObjectHashMap.entrySet();
            for (Map.Entry<Character, Integer> entry : entries) {
                if (entry.getValue()>=2){
                    return true;
                }
            }
        }


        return false;

    }
}
class Solution {

    int[] src;

    int[] xin;

    Random random=new Random();




    public Solution(int[] nums) {
        src=nums;
        xin=new int[src.length];

        for (int i = 0; i < src.length; i++) {
            xin[i]=src[i];
        }

    }

    public int[] reset() {
        return src;
    }

    public int[] shuffle() {

        for (int i = 0; i < xin.length-1; i++) {
            //i-src.lenth-1
            int i1 = random.nextInt(xin.length - i);

            int temp=xin[i1];
            xin[i1]=xin[i];
            xin[i]=temp;
        }



        return xin;
    }

//    public static void main(String[] args) {
//
//        int[] iniy={1,2,3};
//        Solution solution = new Solution(iniy);
//        System.out.println(Arrays.toString(solution.shuffle()));
//        System.out.println(Arrays.toString(solution.reset()));
//        System.out.println(Arrays.toString(solution.shuffle()));
//    }



    public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
        //

        int jinzhi=minutesToTest/minutesToDie+1;

        int value=1;
        int count=0;

        while (value<buckets){
            value=value*jinzhi;
            count++;
        }
        //得到数量
    return count;
    }


    //ceil floor round
//    https://blog.csdn.net/aouixh/article/details/53483556?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163782322616780255289571%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=163782322616780255289571&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-53483556.first_rank_v2_pc_rank_v29&utm_term=ceil&spm=1018.2226.3001.4187

    //ceil 此函数是向上取整，它返回的是大于或等于函数参数,并且与之最接近的整数，

//    2.3  2.6   -2.3   -2.6
//    2    3     -2     -2




    public static void main(String[] args) {
        System.out.println(Math.ceil(2.3));
        System.out.println(Math.ceil(2.6));
        System.out.println(Math.ceil(-2.3));
        System.out.println(Math.ceil(-2.6));


    }






    //AES 加密 解密



}